#include <iostream>
#include <vector>
#include <string>

class Test {
public:
    Test() { std::cout << "Test()" << std::endl; }
    Test(const Test&) { std::cout << "Test(const Test&)" << std::endl; }
    Test(Test&&) { std::cout << "Test(Test&&)" << std::endl; }
};

class Wdiget {
private:
    std::vector<Test> vt;
public:
    Wdiget() { vt.reserve(10); }

public:
    void AddVt(const Test& t) {
        vt.push_back(t);
    }

    void AddVt(Test&& t) {
        vt.push_back(std::move(t));
    }

    template<typename T>
    void AddTest(T&& t) {
        vt.push_back(std::forward<T>(t));
    }

    void addTest(Test t) {
        vt.push_back(std::move(t));
    }
};

class Passward {
private:
    std::string pwd;

public:
    //newpwd 值传递
    //必定会分配内存
    void setPwd(std::string newpwd)
    {
        pwd = std::move(newpwd);
    }

    //当 newpwd 长度 < pwd 时
    //pwd 不会重新分配内存
    void SetPwd(const std::string& newpwd)
    {
        pwd = newpwd;
    }
};

int main() {
    Test t;

    Wdiget w;
    w.AddVt(t);
    std::cout << "=============" << std::endl;
    w.AddVt(Test());

    std::cout << "-------------" << std::endl;

    Test t1;
    w.AddTest(t1);
    std::cout << "=============" << std::endl;
    w.AddTest(Test());

    std::cout << "-------------" << std::endl;

    Test t2;
    w.addTest(t2);
    std::cout << "=============" << std::endl;
    w.addTest(Test());

    return 0;
}